<?php 
include 'config.php';
include 'createdb.php';
//Annahme der Abstimmung
if(isset($_POST['Vereine']) || isset($_POST['sonstiger_Verein'])){
	if(NULL!=$_POST['sonstiger_Verein']){
		$verein = mysql_real_escape_string ($_POST['sonstiger_Verein']);
	}elseif(NULL!=$_POST['Vereine']){
		$verein = mysql_real_escape_string ($_POST['Vereine']);
	}

	$addString = "UPDATE `Vereine` SET `stimmen`=`stimmen` + 1 WHERE `verein`='$verein'";

	$addition = mysql_query($addString);

	$there = mysql_query("SELECT `verein` FROM `Vereine` WHERE `verein` = '$verein'") OR die(mysql_error());
	$foo = mysql_fetch_array($there);

	if($addition){
		if(count($foo)<2){
			$sqlStringsss = "INSERT INTO  `ue_1_a`.`Vereine` (`verein` ,`stimmen`) VALUES ('$verein',  '$addition');";
			$sql = mysql_query($sqlStringsss) OR die(mysql_error());
		}
	}
	$action = 'show';
}
$sum = mysql_query("SELECT SUM(`stimmen`) as s FROM `Vereine`") OR die(mysql_error());
$sum = mysql_fetch_array($sum); 
$fooo = mysql_query("SELECT `verein` FROM `Vereine`") OR die(mysql_error());
include '../header.php';
?>
	<title>&Uumlbung 1a</title>
	</head>
	<body class="background Vereine">
	<div id="uebung" >
	<a class="dlbutton" href="/">Home</a>
		<form id="Vereine" method="post" name="stimme" onsubmit="return checkchoice()">
			<span class="white">Vereine:</span> 
			<select name="Vereine" class="block">
			<option></option>
			<?php
				while($fetch = mysql_fetch_array($fooo)){
					echo '<option>'. $fetch["verein"] .'</option>';
				};
			?>
			</select>
			<span class="white">Sonstiger Verein:</span> 
			<input name="sonstiger_Verein" size=20 maxlength=80 class="block">
			<input type="submit" class="dlbutton" value="Abschicken">
		</form>
		<?php 
		switch ($action){
			case 'show':
				echo '<p class="white">Stimmen: '. $sum['s'] .'</p><a class="dlbutton" href="ergebins.php">Voting Ergebnisse</a>';
			break;
		}
		?>
	</div>
	</body>
</html>